package com.sxkj.service.pay;

import com.sxkj.common.pay.xypay.SwiftpassConfig;
import com.sxkj.common.pay.xypay.XYPay;
import com.sxkj.common.pay.xypay.XYPayConstants;
import com.sxkj.common.utils.SignUtils;
import com.sxkj.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Zhang Xingliang
 * @description 只提供支付相关接口方法，与业务解耦，不允许写业务内容
 * @date 9:30 2020/1/3
 **/
@Service
public class XyPayService {

    private static final Logger logger = LoggerFactory.getLogger(XyPayService.class);

    @Autowired
    private SwiftpassConfig config;

    /**
     * @param data = new HashMap<>();
     *             data.put("mch_id", "403590159100");//商户号
     *             data.put("total_fee", "1");//单位：分 整数字符串,发红包0.3元，此处填30
     *             data.put("out_trade_no", orderId);
     *             data.put("auth_code", "135519502396000000");
     *             data.put("device_info", "pos001");//终端设备号，商户自定义。特别说明：对于QQ钱包支付，此参数必传，否则会报错。
     *             data.put("key", "");//商户秘密要
     * @return java.util.Map<java.lang.String, java.lang.String>
     * @author Zhang Xingliang
     * @description 兴业付款码支付，请严格按照demo格式传入数据 不可多或少
     * @date 20:59 2020/1/1
     **/
    public Map<String, String> micropay(Map<String, String> data) throws Exception {
        Map<String, String> resp = new XYPay(config).micropay(data);
        return resp;
    }

    /**
     * @param data data = new HashMap<>();
     *             data.put("mch_id", "403590159100");//商户号
     *             data.put("out_trade_no", out_trade_no);
     *             data.put("transaction_id", transaction_id);
     *             data.put("sign_type", "MD5");
     *             data.put("key", "");//商户秘密要
     * @return java.util.Map<java.lang.String, java.lang.String>
     * @author Zhang Xingliang
     * @description 查询订单状态
     * @date 20:00 2019/12/30
     **/
    public Map<String, String> unifiedTradeQuery(Map<String, String> data) throws Exception {
        Map<String, String> resp = new XYPay(config).unifiedTradeQuery(data);
        return resp;
    }

    /**
     * @param data requestMap = new HashMap<>();
     *             requestMap.put("mch_id", "403590159100");//商户号
     *             requestMap.put("out_trade_no", out_trade_no);
     *             requestMap.put("transaction_id", transaction_id);
     *             requestMap.put("sign_type", "MD5");
     * @return java.util.Map<java.lang.String, java.lang.String>
     * @author Zhang Xingliang
     * @description 撤销订单
     * @date 20:00 2019/12/30
     **/
    public Map<String, String> unifiedMicropayReverse(Map<String, String> data) throws Exception {
        Map<String, String> resp = new XYPay(config).unifiedMicropayReverse(data);
        return resp;
    }


    /**
     * @param data requestMap = new HashMap<>();
     *             requestMap.put("mch_id", "403590159100");//商户号
     *             requestMap.put("out_trade_no", out_trade_no);//订单流水
     *             requestMap.put("total_fee", total_fee);//交易金额 单位分
     *             requestMap.put("sub_openid", sub_openid);//微信公众号对应的openid
     *             requestMap.put("sign_type", "MD5");//签名默认 加密方式MD5
     * @return java.util.Map<java.lang.String, java.lang.String>
     * @author Zhang Xingliang
     * @description 初始化JSAPI请求，通过生成pay_info来进行交互验证。 微信网页发起支付前调用此方法
     * @date 20:00 2019/12/30
     **/
    public Map<String, String> weixinJsPay(Map<String, String> data) throws Exception {
        Map<String, String> resp = new XYPay(config).weixinJsPay(data);
        return resp;
    }
}
